package cn.mw.cmdb.param;

import cn.mw.cmdb.entity.InstanceInfo;
import cn.mw.cmdb.entity.InventoryWorkAssets;
import cn.mw.cmdb.service.ServiceChoose;
import cn.mw.cmdb.service.impl.InventoryWorkAssetsServiceImpl;
import cn.mw.cmdb.util.CMDBTool;
import cn.mw.components.mongodb.entity.CriteriaOpsType;
import cn.mw.components.mongodb.entity.SearchParam;
import cn.mw.components.mongodb.entity.SubCondition;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Author shenwenyi
 * @Date 2024/6/4 23:54
 * @PackageName:cn.mw.cmdb.param
 * @ClassName: InventoryWorkAssetsParam
 * @Description: TODD
 * @Version 1.0
 */
@Data
public class InventoryWorkAssetsParam extends SearchParam implements ServiceChoose,SearchParamConvert{

    private List<String> ids;

    private String inventoryWorkInfoId;
    private List<String> inventoryWorkInfoIds;

    @Override
    public void convert() {
        //资产实例Id查询参数
        String inventoryWorkInfoId = getInventoryWorkInfoId();
        if (StringUtils.hasText(inventoryWorkInfoId)) {
            this.addSubCondition(CMDBTool.getFieldName(InventoryWorkAssets::getInventoryWorkInfoId)
                    , new SubCondition(CriteriaOpsType.is.name(), inventoryWorkInfoId));
        }
        List<String> inventoryWorkInfoIds1 = getInventoryWorkInfoIds();
        if (CollectionUtils.isNotEmpty(inventoryWorkInfoIds1)) {
            this.addSubCondition(CMDBTool.getFieldName(InventoryWorkAssets::getInventoryWorkInfoId)
                    , new SubCondition(CriteriaOpsType.in.name(), inventoryWorkInfoIds1));
        }
    }

    @Override
    public String getServiceId() {
        return InventoryWorkAssetsServiceImpl.ID;
    }
}
